
import 'package:share_fit/app/helper/storage_helper.dart';
import 'package:share_fit/app/tools/app_const.dart';

class UnitUtil {

  static bool isHeightUnitUS() {
    var heightUnit = StorageHelper.read(AppConst.spaceUnitLength, defaultValue: AppConst.unitsUS);
    return  heightUnit == AppConst.unitsUS;
  }

  static bool isWeightUnitUS() {
    var weightUnit = StorageHelper.read(AppConst.spaceUnitWeight, defaultValue: AppConst.unitsUS);
    return  weightUnit == AppConst.unitsUS;
  }

  static List<String> generateListData(int start, int end) {
    List<String> res = [];
    for (var i = start;i <= end; i++) {
      res.add(i.toString());
    }

    return res;
  }

  static List<String> getHeightList() {

    int start = 100;
    int end = 260;
    if (isHeightUnitUS()) {
      start = 40;
      end = 100;
    }

    return generateListData(start, end);
  }

  static List<String> getWeightList() {
    int start = 20;
    int end = 200;
    if (isWeightUnitUS()) {
      start = 50;
      end = 500;
    }

    return generateListData(start, end);
  }

  static List<String> getTargetWeightList() {
    int start = 20;
    int end = 250;
    if (isWeightUnitUS()) {
      start = 50;
      end = 580;
    }

    return generateListData(start, end);
  }

  static int getLengthUnit() {
    return StorageHelper.read(AppConst.spaceUnitLength, defaultValue: 0);
  }

  static String getLengthUnitName() {
    return isHeightUnitUS() ?'in':'cm';
  }

  static String getWeightUnitName() {
    return isWeightUnitUS() ?'lb':'kg';
  }

  // 转换函数：将英寸转换为厘米
  static int inchesToCm(double inches) {
    return (inches * 2.54).round().toInt();
  }

  static int cmToInches(double cm) {
    return (cm / 2.54).round().toInt();
  }

  static int kgToLb(double kg) {
    return (kg * 2.205).round().toInt();
  }

  static int lbToKg(double lb) {
    return (lb / 2.205).round().toInt();
  }

  static double milesToKm(double miles) {
    return miles * 1.609;
  }

}